import { computed } from 'vue';
import { hDate, yyyymmdd } from 'utils/date';
export default function (state) {
  const { schedules, task } = state;

  let handleNextDay = () => {
    task.date = new Date(task.date.getTime() - 24 * 60 * 60 * 1000);
  };

  let handlePrevDay = () => {
    task.date = new Date(task.date.getTime() + 24 * 60 * 60 * 1000);
  };
  task.dateDisplayed = computed(() => hDate(task.date));

  // watch(
  //   () => schedules,
  //   () => {
  //     if (schedules.hasOwnProperty(yyyymmdd(task.date))) {
  //       if (schedules[yyyymmdd(task.date)].learnInfo.length > 0)
  //         task.learning = schedules[yyyymmdd(task.date)].learnInfo.join('\n');
  //     }
  //     return '没有';
  //   },
  // );
  task.learning = computed(() => {
    if (schedules.hasOwnProperty(yyyymmdd(task.date))) {
      if (schedules[yyyymmdd(task.date)].learnInfo.length > 0)
        return schedules[yyyymmdd(task.date)].learnInfo.join('\n');
    }
    return '没有';
  });

  task.review = computed(() => {
    if (schedules.hasOwnProperty(yyyymmdd(task.date))) {
      if (schedules[yyyymmdd(task.date)].reviewInfo.length > 0)
        return schedules[yyyymmdd(task.date)].reviewInfo.join('\n');
    }
    return '没有';
  });
  // task.date = new Date();
  return {
    handlePrevDay,
    handleNextDay,
  };
}
